﻿using System;
using System.Collections.Generic;
using System.Text;
using IO=System.IO;

namespace LibUpdate
{
    internal class DirectoryAction : IUpdateAction
    {
        private string _VerStr;
        private string _AppPath;
        private File _ActionFile;

        #region IUpdateAction 成员

        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public bool Add()
        {
            try
            {

                IO.DirectoryInfo d = new System.IO.DirectoryInfo(Get_ToFilePath());
                if(!d.Exists)
                d.Create();
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        public bool Delete()
        {
            try
            {

                IO.DirectoryInfo d = new System.IO.DirectoryInfo(Get_ToFilePath());
                if (!d.Exists)
                    d.Delete();
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 暂时不可用
        /// </summary>
        /// <returns></returns>
        public bool Edit()
        {
            return false;
        }

        public bool Update()
        {
            throw new NotImplementedException();
        }

        public bool Exec()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IUpdateAction 成员

        public File ActionFile
        {
            get
            {
                return _ActionFile;
            }
            set
            {
                _ActionFile = value;
            }
        }

        public string AppPath
        {
            get
            {
                return _AppPath;
            }
            set
            {
                _AppPath = value;
            }
        }

        #endregion

        #region IUpdateAction 成员


        public string VerStrDir
        {
            get
            {
                return _VerStr;
            }
            set
            {
                _VerStr = value;
            }
        }

        /// <summary>
        /// 获得添加路径
        /// </summary>
        protected string Get_ToFilePath()
        {
            return AppPath + "\\" + _ActionFile.Path + "\\" + _ActionFile.FileName;
        }
        #endregion
    }
}
